﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xarmarin.GoldFinger.Engine.Core;
using Xarmarin.GoldFinger.Models.AutoModels;
using Xarmarin.GoldFinger.ViewModels;

namespace Xarmarin.GoldFinger.Views.Subject
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SubListPage : ContentPage
    {
        SubjectViewModel viewModel;
        public SubListPage()
        {
            InitializeComponent();
            //绑定角色
            Services.SubjectDataStore.BindCurrentSub();
            Title ="当前分身："+KzContext.CurrSubject.RealName;
            BindingContext = viewModel = new SubjectViewModel();
        }

        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (!(e.Item is Auto_Subject item)) return;
            var r =
                await DisplayAlert("提示", "确定化身“"+item.RealName+"”继续修仙吗？", "确定", "取消");
            if (r)
            {
                Services.SubjectDataStore.BindCurrentSub(item);
                Application.Current.MainPage = new NavigationPage(SinglePageManager.MainPage);
            }

            //Deselect Item
            ((ListView)sender).SelectedItem = null;
        }
    }
}
